<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>选择调研试题列表</title>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script src='<c:url value="/js/boot.js"></c:url>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
.mini-pager {
    height: 40px !important;
}

//弹出
/* #dialog {
	position: absolute;
	top: 60px;
	width: 65%;
	left: 17.5%;
	background: rgb(252, 252, 252);
	z-index: 1000;
} */

#abc {
	position: absolute;
	top: 20%;
	left: 360px;
	z-index: 2;
}

.maskLayer {
	z-index: 10;
	opacity: 0.3;
	filter: alpha(opacity = 30);
	background-color: #ccc;
}

.questions_stems {
	border: 1px solid #a4a4a4;
	padding: 6px 12px;
	margin: 30px 30px 10px 30px;
	font-size: 16px;
	font-family: "微软雅黑";
	color: #8B8B8B;
}

.options {
	border: 1px solid #a4a4a4;
	padding: 10px 25px;
	margin: 20px 30px;
	font-size: 16px;
	font-family: "微软雅黑";
	color: #8B8B8B;
}

.options>li {
	padding: 10px 15px;
	font-size: 16px;
	font-family: "微软雅黑";
	color: #8B8B8B;
}

.answer {
	border: 1px solid #a4a4a4;
	padding: 10px;
	margin: 20px 30px;
	font-size: 16px;
	font-family: "微软雅黑";
	color: #8B8B8B;
}

.answer_detail {
	border: 1px solid #a4a4a4;
	padding: 10px;
	margin: 20px 30px 40px 30px;
	font-size: 16px;
	font-family: "微软雅黑";
	color: #8B8B8B;
}

.answer_detail>p {
	margin-left: 80px;
	max-height: 400px;
	overflow-y: auto;
}
</style>
<script>
	var testType = [ {
		id : "单选题",
		text : "单选题"
	}, {
		id : "多选题",
		text : "多选题"
	}, {
		id : "判断题",
		text : "判断题"
	}, {
		id : "解答题",
		text : "解答题"
	} ];
</script>


</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="100px"><a class="mini-button" id="resetBtn"
					iconCls="icon-reset" plain="true" onclick="reloadList">刷新</a></td>
				<td width="100px"><a class="mini-button" id="okBtn"
					iconCls="icon-ok" plain="true" onclick="confirm()">确定</a></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;查询日期:&nbsp;&nbsp;<input
						id="starting" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="起始期间..." nullItemText="&lt;无&gt;" />
						<span
						style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect" tooltip="查询" plain="true">查询</a>
				</span></td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id='panLeft' size="400" showCollapseButton="true"
			style="padding: 0px; height: 100%; width: 100%;">
			<div id="datagrid1" class="mini-datagrid gridFull"
				borderStyle="border:1;" showReloadButton="true" pagesize="20"
				sizeList="[20,50,100,200]" allowCellWrap="true"
				allowHeaderWrap="true" idField="No" multiSelect="true"
				showPager="true" allowAlternating="true"
				ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
				style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
				collapseGroupOnLoad="false" showColumnsMenu="true"
				showFilterRow="true" onshowrowdetail="onShowRowDetail">
				<div property="columns">
					<div type="checkcolumn" width="40px"></div>
					<div field="Action" width="70px" headerAlign="center"
						align="center">
						<a class="mini-button" property="filter" id="removeBtn"
							iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
						</a>
					</div>
					<div field="class_id" width="100px" headerAlign="center"
						align="left" allowSort="true">
						题目类型<input id="filter1" property="filter" class="mini-combobox"
							style="width: 100%;" data=testType onValueChanged="onselect"
							emptyText="筛选..." onenter="onselect" />
					</div>
					<div field="question" width="260px" headerAlign="center"
						align="left" allowSort="true">
						题干<input id="filter2" property="filter"
							class="mini-buttonedit searchbox" style="width: 100%;"
							onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
					</div>
					<div field="creater" width="100px" headerAlign="center"
						align="left" allowSort="true">
						编制人<input id="filter4" property="filter"
							class="mini-buttonedit searchbox" style="width: 100%;"
							onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
					</div>
					<div field="createTime" width="185px"
						dateFormat="yyyy-MM-dd hh:mm:ss" headerAlign="center"
						align="center" allowSort="true">编制时间</div>
					<div name="emptyCol" width='100%' headerAlign="center"
						align="center" cellStyle="padding:0;"></div>
				</div>
			</div>
		</div>
	</div>
	<div id="dialog" style="display: none;">
		<div class="close">
			<img src="<c:url value="/share/img/icon/close_02.png"></c:url>"
				onclick="closeBg()" alt="关闭" style="margin-right: -40px;" />
		</div>
		<div class="questions_stems">
			<font id="question_stem"></font>
		</div>
		<ul class="options" id="select_options">
		</ul>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var rootPath = '${rootPath}';
		var type = '${type}';
		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter4 = mini.get("filter4");
		var splitpan = mini.get("splitterPan");
		var starting = mini.get("starting");
		var ending = mini.get("ending");
		$(function() {
			loadGrid1();
		});
		//双击
		function onselect() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue4 = filter4.getValue();
			var start = starting.getValue();
			var end = ending.getValue();
			filterHelper.clearFilterData();
			if (start && end && start > end) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (start != "") {
				var startTime = new Date(start);
				var tempTime = startTime.valueOf();
				startTime += 24 * 60 * 60 * 1000;
				startTime = new Date(tempTime);
				var year = startTime.getYear() + 1900;
				var month = startTime.getMonth() + 1;
				if (month < 10) {
					month = "0" + month;
				}
				var day = startTime.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				start = year + "-" + month + "-" + day;
				var filterdata = filterHelper.formFilterData("createTime",
						start, '', 'GREATER_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (end != "") {
				var filterdata = filterHelper.formFilterData("createTime", end,
						'', 'LESS_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("class_id",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("question",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue4 != "") {
				var filterdata = filterHelper.formFilterData("creater",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/surveyPaper/questionList/' />" + type;
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filter4.setValue();
			filter4.setText();
			starting.setValue();
			ending.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;

			if (field == "Action") {
				var id = row.id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showTest('
						+ id + ',\'' + row.class_id + '\')">[预览]</a>';
			}

		}
		function reloadList() {
			datagrid1.reload();
		}

		function showTest(id, type) {
			var url = rootPath + "/surveyTest/testInfo/" + id;
			$.ajax({
				url : url,
				method : "post",
				dataType : "json",
				data : {},
				success : function(data) {
					if (data) {
						showDetail(data, type);
					} else {
						alert("获取信息失败！");
					}
				},
				error : function() {
					alert("失败！");
				}
			});
		}
		function closeBg() {
			$("#dialog").hide();
			$("#abc").removeClass("maskLayer");
		}
		function showDetail(data, question_type) {
			$("#dialog").show();
			$("#dialog").css({
				"position" : "absolute",
				"top" : "60px",
				"width" : "65%",
				"left" : "17.5%",
				"background" : "rgb(252, 252, 252)",
				"z-index" : "1000"
			});
			$("#question_stem").html(data.question);
			if (question_type == "单选题") {
				selects = data.selects;//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr = "";
				for (var i = 0; i < arr.length; i++) {
					var str = String.fromCharCode(i + 65);
					Htmstr += "<li>" + "<font>" + str + '、' + arr[i]
							+ "</font>" + "</li>";
				}
				$("#select_options").html(Htmstr);
			} else if (question_type == "多选题") {
				selects = data.selects;//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr = "";
				for (var i = 0; i < arr.length; i++) {
					var str = String.fromCharCode(i + 65);
					Htmstr += "<li>" + "<font>" + str + '、' + arr[i]
							+ "</font>" + "</li>";
				}
				$("#select_options").html(Htmstr);
			} else if (question_type == "判断题") {
				$("#select_options").html(
						"<li><font>是</font></li><li>" + "<font>否</font></li>");
			} else if (question_type == "问答题") {
				$("#select_options").html("<p style =\"height:40px\"></p>");
			}
		}
		function confirm() {
			var ids = datagrid1.getSelecteds();
			if (ids.length < 1) {
				mini.alert("请选择至少一道试题！");
			} else {
				//parent.source_id = ids[0].id;
				var str = "";
				for (var i = 0; i < ids.length; i++) {
					if (i == 0) {
						str = ids[0].id;
					} else {
						str += "," + ids[i].id;
					}
				}
				CloseWindow(str.toString());
			}
		}
		function CloseWindow(action) {
			if (window.CloseOwnerWindow) {
				return window.CloseOwnerWindow(action);
			} else {
				window.close();
			}
		}
	</script>
</body>
</html>